package org.mtmi.midi;

import org.mtmi.ui.M;
import org.mtmi.ui.controls.Slider;
import org.mtmi.ui.controls.listeners.ValueChangedListener;
import org.mtmi.ui.controls.listeners.ValueEvent;
import org.mtmi.ui.scenes.Scene;

import rwmidi.MidiOutput;

public class SendMidiCCSlider extends Slider implements ValueChangedListener {

	int midiChannel;
	int ccNumber;
	MidiOutput midiOutput;
	
	public SendMidiCCSlider(Scene scene) {
		super(scene, M.SCENE_CONTROL);
		addValueChangedListener(this);
	}
	
	public SendMidiCCSlider(Scene scene,boolean isHoriz,int midiChannel, int ccNumber,	int ccMinvalue, int ccMaxValue) {
		super(scene,isHoriz,0,ccMinvalue,ccMaxValue, M.SCENE_CONTROL);
		addValueChangedListener(this);
		this.midiChannel = midiChannel;
		this.ccNumber = ccNumber;
	}
	
	public MidiOutput getMidiOutput() {
		return midiOutput;
	}
	
	public void setMidiOutput(MidiOutput midiOutput) {
		this.midiOutput = midiOutput;
	}
	
	public int getMidiChannel() {
		return midiChannel;
	}
	
	public void setMidiChannel(int midiChannel) {
		this.midiChannel = midiChannel;
	}
	
	public int getCCNumber() {
		return ccNumber;
	}
	
	public void setCCNumber(int ccNumber) {
		this.ccNumber = ccNumber;
	}
	
	public int getCCMinValue() {
		return this.getMinValue();
	}
	
	public void setCCMinValue(int ccMinValue) {
		this.setMinValue(ccMinValue);
	}
	
	public int getCCMaxValue() {
		return this.getMaxValue();
	}
	
	public void setCCMaxValue(int ccMinValue) {
		this.setMinValue(ccMinValue);
	}
	
	private void sendCCMessage(int ccValue) {
		// Debug
		System.out.println("sending Control Change " + ccNumber + "on channel "
				+ midiChannel + " with value " + ccValue);
		midiOutput.sendController(midiChannel, ccNumber, ccValue);
	}
	

	@Override
	public void valueChanged(ValueEvent event) {
		sendCCMessage(event.newValue);
		
	}




	



}
